{{#supportPython2}}
#!/usr/bin/env python
{{/supportPython2}}
{{^supportPython2}}
#!/usr/bin/env python3
{{/supportPython2}}

import connexion
from connexion.decorators import produces
from six import iteritems
from {{modelPackage}}.base_model_ import Model


class JSONEncoder(produces.JSONEncoder):
    include_nulls = False

    def default(self, o):
        if isinstance(o, Model):
            dikt = {}
            for attr, _ in iteritems(o.swagger_types):
                value = getattr(o, attr)
                if value is None and not self.include_nulls:
                    continue
                attr = o.attribute_map[attr]
                dikt[attr] = value
            return dikt
        return produces.JSONEncoder.default(self, o)


if __name__ == '__main__':
    app = connexion.App(__name__, specification_dir='./swagger/')
    app.app.json_encoder = JSONEncoder
    app.add_api('swagger.yaml', arguments={'title': '{{appDescription}}'})
    app.run(port={{serverPort}})
